package yxy.game.pm2.command.shop;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ShopMessage;
import yxy.game.pm2.module.CurrencyHandle;
import yxy.game.pm2.module.shop.HeroShopModule;
import yxy.game.pm2.module.shop.handle.HeroShopHandle;

/** 商店 武将商店 */
@MessageType(proto = Command.HeroShop, classtype = ShopMessage.HeroShopRequest.class)
public class CMD_HeroShop extends Command<ShopMessage.HeroShopRequest> {

	@Override
	public void execute(MessageSource messageSource, ShopMessage.HeroShopRequest request) {
		try {
			String playerCode = messageSource.getTag();

			ShopMessage.HeroShopResponse.Builder response = ShopMessage.HeroShopResponse.newBuilder();

			//根据开服时间和showtime过滤商品是否展示
			response.addAllGoods(new HeroShopHandle().goods(playerCode));

			response.setResetCost(new CurrencyHandle().packPoint(HeroShopModule.ShopRefreshCost()));

			send(messageSource, response, Result.Success);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void send(MessageSource messageSource, ShopMessage.HeroShopResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}

}